package com.yy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.pojo.Dish;
import com.yy.pojo.Survey;
import com.yy.service.SurveyService;
import com.yy.mapper.SurveyMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author yyu
* @description 针对表【t_survey(调查索引表)】的数据库操作Service实现
* @createDate 2023-12-28 15:04:16
*/
@Service
public class SurveyServiceImpl extends ServiceImpl<SurveyMapper, Survey>
    implements SurveyService{

    @Autowired
    private SurveyMapper surveyMapper;
    @Override
    public IPage<Survey> getSurveyList(int pageNum, int pageSize, Survey survey) {
        IPage<Survey> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Survey> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotEmpty(survey.getSurveyTitle())) {
            lambdaQueryWrapper.like(Survey::getSurveyTitle,survey.getSurveyTitle());
        }

        if (ObjectUtils.isNotEmpty(survey.getRestaurantId())) {
            lambdaQueryWrapper.like(Survey::getRestaurantId,survey.getRestaurantId());
        }

        lambdaQueryWrapper.orderByDesc(Survey::getCreateTime);

        surveyMapper.selectPage(page, lambdaQueryWrapper);
        return page;
    }
}




